<?php

namespace App\Http\Controllers\Frontend\User;

use App\Http\Controllers\Frontend\FrontendController;
use App\Http\Resources\Frontend\ApiResource;
use App\Http\Resources\Frontend\UserResource;
use App\Models\UserRelation;
use App\Services\Contract\UserRelationServiceInterface;
use Illuminate\Http\Request;
use App\Http\Requests\Frontend\User\RelationRequest;
class RelationController extends FrontendController
{
    protected $userRelationService;
    public function __construct(UserRelationServiceInterface $userRelationService)
    {
        $this->userRelationService = $userRelationService;
    }

    //好友列表
    function index(Request $request) {
        $data = $this->userRelationService->paginate([
            'user_id' => auth()->id(),
        ],15);
        return new ApiResource('ok',200,$data);
    }

    function create(RelationRequest $request){
        $result = $this->userRelationService->create($request->postFillData());
        if($result){
            return new ApiResource();
        }else{
            return new ApiResource($this->userRelationService->getError(),0);
        }
    }
}
